package com.isorf.controller;

import com.github.pagehelper.PageInfo;
import com.isorf.pojo.ShoeSize;
import com.isorf.service.ShoeSizeService;
import com.isorf.util.ResponseResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "鞋子尺寸管理")
@RestController
@RequestMapping("/shoeSize")
public class ShoeSizeController {
    @Autowired
    private ShoeSizeService shoeSizeService;

    /**
     * 新增鞋子尺寸
     */
    @PostMapping("/add")
    public ResponseResult<Boolean> addShoeSize(@RequestBody ShoeSize shoeSize) {
        Boolean result = shoeSizeService.addShoeSize(shoeSize);
        if (result) {
            return ResponseResult.success(ResponseResult.SUCCESS, "添加成功", result);
        } else {
            return ResponseResult.failure(ResponseResult.FAILED, "添加失败");
        }
    }

    /**
     * 删除鞋子尺寸
     */
    @PostMapping("/delete")
    public ResponseResult<Boolean> deleteShoeSize(@RequestParam int sizeId) {
        Boolean result = shoeSizeService.deleteShoeSize(sizeId);
        if (result) {
            return ResponseResult.success(ResponseResult.SUCCESS, "删除成功", result);
        } else {
            return ResponseResult.failure(ResponseResult.FAILED, "删除失败");
        }
    }

    /**
     * 更新鞋子尺寸
     */
    @PostMapping("/update")
    public ResponseResult<Boolean> updateShoeSize(@RequestBody ShoeSize shoeSize) {
        Boolean result = shoeSizeService.updateShoeSize(shoeSize);
        if (result) {
            return ResponseResult.success(ResponseResult.SUCCESS, "更新成功", result);
        } else {
            return ResponseResult.failure(ResponseResult.FAILED, "更新失败");
        }
    }

    /**
     * 根据ID查询鞋子尺寸
     */
    @GetMapping("/getById")
    public ResponseResult<ShoeSize> getShoeSizeById(@RequestParam int sizeId) {
        ShoeSize result = shoeSizeService.getShoeSizeById(sizeId);
        if (result != null) {
            return ResponseResult.success(ResponseResult.SUCCESS, "查询成功", result);
        } else {
            return ResponseResult.failure(ResponseResult.FAILED, "查询失败");
        }
    }

    /**
     * 分页查询鞋子尺寸
     */
    @GetMapping("/pageList")
    public ResponseResult<PageInfo<ShoeSize>> pageList(@RequestParam(defaultValue = "1") int pageNum, 
                                                       @RequestParam(defaultValue = "5") int pageSize) {
        PageInfo<ShoeSize> result = shoeSizeService.pageList(pageNum, pageSize);
        if (result != null && result.getList().size() > 0) {
            return ResponseResult.success(ResponseResult.SUCCESS, "查询成功", result);
        } else {
            return ResponseResult.failure(ResponseResult.FAILED, "查询失败");
        }
    }

    /**
     * 查询全部鞋子尺寸
     */
    @GetMapping("/getAll")
    public ResponseResult<List<ShoeSize>> getAllShoeSizes() {
        List<ShoeSize> result = shoeSizeService.getAllShoeSizes();
        if (result != null && result.size() > 0) {
            return ResponseResult.success(ResponseResult.SUCCESS, "查询成功", result);
        } else {
            return ResponseResult.failure(ResponseResult.FAILED, "没有鞋子尺寸信息");
        }
    }
} 